package com.desire.config;

import com.desire.interceptor.FeignAuthInterceptor;
import feign.Logger;
import feign.Request;
import feign.RequestInterceptor;
import feign.auth.BasicAuthRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @Author: littleDesire
 * @Date: 2022-06-08 17:48
 * @Version: 1.0
 */
@Configuration
public class FeignConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    /**
     * 基本认证请求拦截器
     */
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("admin", "123");
    }

    /**
     * 自定义token认证
     */
    //@Bean
    public RequestInterceptor requestInterceptor() {
        return new FeignAuthInterceptor();
    }

    /**
     * 超时时间配置
     */
    @Bean
    public Request.Options options() {
        // this(10L, TimeUnit.SECONDS, 60L, TimeUnit.SECONDS, true); 默认值
        return new Request.Options(10L, TimeUnit.SECONDS, 60L, TimeUnit.SECONDS,true);
    }

}
